import BaseModel from './.model';
import { Table, Column, DataType, HasMany, BelongsToMany } from 'sequelize-typescript';
import PermissionModel from './permission.model';
import UserModel from './user.model';
import RolePermissionModel from './role-permission.model';
import UserRoleModel from './user-role.model';

@Table({ tableName: 'roles' })
export default class RoleModel extends BaseModel {
  /** 角色名称 */
  @Column({ type: DataType.STRING, comment: '角色名称' })
  name!: string;

  /** 角色权限 */
  @BelongsToMany(() => PermissionModel, () => RolePermissionModel)
  permissions?: PermissionModel[];

  /** 拥有该角色的用户 */
  @BelongsToMany(() => UserModel, () => UserRoleModel)
  users?: UserModel[];
}
